//
//  GMAnserCell.m
//  Teecloud
//
//  Created by 小熊 on 2018/11/12.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "GMAnserCell.h"
#import "GMSubjectsModel.h"
@interface GMAnserCell()
/**是否回答正确*/
@property (weak, nonatomic) IBOutlet UILabel *typeName;
@property (weak, nonatomic) IBOutlet UILabel *rightAnser;
@property (weak, nonatomic) IBOutlet UILabel *userTime;
@property (weak, nonatomic) IBOutlet UILabel *avTime;
@property (weak, nonatomic) IBOutlet UILabel *correctRate;
@property (weak, nonatomic) IBOutlet UILabel *EasyError;
@property (weak, nonatomic) IBOutlet UIButton *colectBtn;
@property (nonatomic, copy) NSString *direction;

@end
@implementation GMAnserCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setModel:(GMSubjectsModel *)model{
    _model = model;
    if ([model.Answer isEqualToString:model.StandardAnswer]) {
        self.typeName.text = @"回答正确";
        self.typeName.textColor = [UIColor colorWithHexString:@"00B432"];
    }else{
        self.typeName.text = @"回答错误";
        self.typeName.textColor = kRedColor;
    }
    self.rightAnser.text = [NSString stringWithFormat:@"正确答案%@",model.StandardAnswer];
    self.userTime.text = model.UseTime;
    self.avTime.text = model.AverageTime;
    self.correctRate.text = model.CorrectRate;
    self.EasyError.text = model.EasyErrorItemCode;
    if (model.IsCollected) {
        self.colectBtn.selected = YES;
        self.direction = @"2";
    }else{
        self.colectBtn.selected = NO;
        self.direction = @"1";
    }
}
- (IBAction)colectBtnClick:(UIButton *)sender {
    NSDictionary *dict= @{@"from":FROM_IOS,
                          @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                          @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                          @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                          @"subjectId":self.model.Id,
                          @"direction":self.direction
                          };
    [MBProgressHUD showHUDAddedTo:kGHAlertViewKeyWindow animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=PostSubjectCollect&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:kGHAlertViewKeyWindow animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                if ([self.direction isEqualToString:@"1"]) {
                    self.model.IsCollected = YES;
                }else{
                    self.model.IsCollected = NO;
                }
                [[NSNotificationCenter defaultCenter] postNotificationName:@"updata" object:nil];
            }else{
               [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:kGHAlertViewKeyWindow];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"网络错误" toView:kGHAlertViewKeyWindow];
        }
    }];

}
@end
